package com.example.pathprotectsystem.mapper;

import com.example.pathprotectsystem.pojo.BindModel;
import com.example.pathprotectsystem.pojo.TaskModel;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BindMapper {
    @Insert("insert into task(taskType,taskName,taskTime,status,userId,pathId,end)" +
            "values(#{taskType},#{taskName},#{taskTime},#{status},#{userid},#{pathid},0)")
    void addtask(String taskType, String taskName, String taskTime, String status, int userid, int pathid);

    @Select("select * from task " +
            "left join path on task.pathId = path.id " +
            "left join user on task.userId = user.id " +
            "where task.taskName like concat('%',concat(#{str},'%')) or " +
            "task.taskType like concat('%',concat(#{str},'%')) or " +
            "task.taskTime like concat('%',concat(#{str},'%')) or " +
            "user.userName like concat('%',concat(#{str},'%')) or " +
            "user.userType like concat('%',concat(#{str},'%')) or " +
            "path.pathName like concat('%',concat(#{str},'%')) or " +
            "path.pavementType like concat('%',concat(#{str},'%')) or " +
            "task.status like concat('%',concat(#{str},'%')) " +
            "order by task.taskTime desc"
            )
    List<BindModel> pathlist(String str);

    @Update("update task set userId = #{userid}, pathId = #{pathid}, taskTime = #{taskTime} where id=#{id}")
    void taskupdate(int userid, int pathid, String taskTime,int id);
    @Delete("delete from task where id = #{id}")
    void taskdelete(int id);
    @Select("select count(*) from task where pathId = #{id}")
    int findPathIdFromTask(int id);
    @Select("select count(*) from task where userId = #{id}")
    int findUserIdFromTask(Integer id);
    @Update("update task set status = '已填写' where id = #{id}")
    void taskupdatestatus(int id);
    @Update("update task set status = '已完成', end = 1 where id = #{id}")
    void taskfinalstatus(int id);
    @Select("select status from task where id =#{id}")
    String getstatus(int id);
    @Select("select pathId from task where id = #{taskId}")
    int getpathid(int taskId);
    @Insert("insert into task(taskType,taskName,taskTime,status,pathId,end)" +
            "values(#{taskType},#{taskName},now(),#{status},#{pathid},0)")
    void AIaddtask(int pathid, String taskType, String taskName, String status);
}
